package com.zenithmind.chat.pojo.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.util.List;

/**
 * AI对话创建DTO
 * 遵循单一职责原则，专门用于创建对话
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "AI对话创建DTO")
public class AiChatCreateDTO extends BaseDTO {
    
    @NotBlank(message = "对话标题不能为空")
    @Size(max = 100, message = "对话标题长度不能超过100个字符")
    @Schema(description = "对话标题", example = "关于Java编程的讨论")
    private String title;
    
    @NotNull(message = "模型类型不能为空")
    @Schema(description = "模型类型(1-OpenAI,2-Ollama,3-Azure,4-Anthropic,5-自定义)", example = "1")
    private Integer modelType;
    
    @NotBlank(message = "模型名称不能为空")
    @Size(max = 50, message = "模型名称长度不能超过50个字符")
    @Schema(description = "模型名称", example = "gpt-3.5-turbo")
    private String modelName;
    
    @Size(max = 2000, message = "系统提示词长度不能超过2000个字符")
    @Schema(description = "系统提示词", example = "你是一个专业的Java编程助手")
    private String systemPrompt;
    
    @Schema(description = "标签列表", example = "[\"编程\", \"Java\"]")
    private List<String> tags;
    
    @Schema(description = "共享类型(0-私有,1-公开,2-指定用户)", example = "0")
    private Integer shareType;
    
    @Schema(description = "共享用户ID列表")
    private List<String> shareUserIds;
    
    @Override
    public boolean isValid() {
        // 自定义验证逻辑
        if (modelType != null && (modelType < 1 || modelType > 5)) {
            return false;
        }
        
        if (shareType != null && (shareType < 0 || shareType > 2)) {
            return false;
        }
        
        // 如果是指定用户共享，必须提供用户ID列表
        if (Integer.valueOf(2).equals(shareType) && 
            (shareUserIds == null || shareUserIds.isEmpty())) {
            return false;
        }
        
        return super.isValid();
    }
    
    @Override
    public String getBusinessKey() {
        return title + ":" + modelType + ":" + modelName;
    }
}
